﻿/*版权声明
 * 
 * 本 WebName:IMIS_ERP 由
 * 河北大学 信管团队 开发
 * 如有任何疑问请联系开发人员
 * 
 * 项目开发者
 * 负责人：朱胜贤
 * 成员：水亚亚、孙旭峰、张文元、项玥、吕芳、吴凡、谢静、李亚慧
 *
 * 如有任何疑问请联系：河北大学信管团队
 * QQ：196396337
 * Email:zagelover@163.com
 * HomePage：http://sxgzs.com/
 *
 * CopyRight (c) 河北大学信管团队 2010~2020
 */

using System;
using System.Data;
using System.Text;
using System.Data.SqlClient;
using IMIS_ERP.DBUtility;//Please add references
namespace IMIS_ERP.DAL
{
    /// <summary>数据访问类:Products_DisCount
    ///     <remarks>2011-01-21 河北大学信管团队</remarks>
    /// </summary>
    public class Products_DisCount
    {
        public Products_DisCount()
        { }
        #region  Method
        /// <summary>是否存在该记录
        ///     <remarks>2011-01-21 河北大学信管团队</remarks>
        /// </summary>
        /// <param name="pdID">编号</param>
        /// <returns>返回是否存在</returns>
        public bool Exists(int pdID)
        {
            int rowsAffected;
            SqlParameter[] parameters = {
					new SqlParameter("@pdID", SqlDbType.Int)};
            parameters[0].Value = pdID;

            int result = DbHelperSQL.RunProcedure("UP_Products_DisCount_Exists", parameters, out rowsAffected);
            if (result == 1)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        /// <summary>增加一条数据
        ///      <remarks>2011-01-21 河北大学信管团队</remarks>
        /// </summary>
        /// <param name="model"></param>
        /// <returns>返回是否添加成功</returns>
        public bool Add(IMIS_ERP.Model.Products_DisCount model)
        {
            SqlParameter[] parameters = {
					new SqlParameter("@pdID", SqlDbType.Int),
					new SqlParameter("@pdProvince", SqlDbType.VarChar,20),
					new SqlParameter("@pdCity", SqlDbType.VarChar,50),
					new SqlParameter("@pdArea", SqlDbType.VarChar,50),
					new SqlParameter("@pdPID", SqlDbType.NVarChar,20),
					new SqlParameter("@pdDisCount", SqlDbType.Decimal,5),
					new SqlParameter("@pdBeginTime", SqlDbType.DateTime),
					new SqlParameter("@pdEndTime", SqlDbType.DateTime)};
            parameters[0].Direction = ParameterDirection.Output;
            parameters[1].Value = model.pdProvince;
            parameters[2].Value = model.pdCity;
            parameters[3].Value = model.pdArea;
            parameters[4].Value = model.pdPID;
            parameters[5].Value = model.pdDisCount;
            parameters[6].Value = model.pdBeginTime;
            parameters[7].Value = model.pdEndTime;

            return DbHelperSQL.GetIsRunOK("UP_Products_DisCount_ADD", parameters);
        }

        /// <summary>更新一条数据
        ///      <remarks>2011-01-21 河北大学信管团队</remarks>
        /// </summary>
        /// <param name="model"></param>
        /// <returns>返回是否修改成功</returns>
        public bool Update(IMIS_ERP.Model.Products_DisCount model)
        {
            SqlParameter[] parameters = {
					new SqlParameter("@pdID", SqlDbType.Int),
					new SqlParameter("@pdProvince", SqlDbType.VarChar,20),
					new SqlParameter("@pdCity", SqlDbType.VarChar,50),
					new SqlParameter("@pdArea", SqlDbType.VarChar,50),
					new SqlParameter("@pdPID", SqlDbType.NVarChar,20),
					new SqlParameter("@pdDisCount", SqlDbType.Decimal,5),
					new SqlParameter("@pdBeginTime", SqlDbType.DateTime),
					new SqlParameter("@pdEndTime", SqlDbType.DateTime)};
            parameters[0].Value = model.pdID;
            parameters[1].Value = model.pdProvince;
            parameters[2].Value = model.pdCity;
            parameters[3].Value = model.pdArea;
            parameters[4].Value = model.pdPID;
            parameters[5].Value = model.pdDisCount;
            parameters[6].Value = model.pdBeginTime;
            parameters[7].Value = model.pdEndTime;

            return DbHelperSQL.GetIsRunOK("UP_Products_DisCount_Update", parameters);
        }

        /// <summary>删除一条数据
        ///      <remarks>2011-01-21 河北大学信管团队</remarks>
        /// </summary>
        /// <param name="pdID">编号</param>
        /// <returns>返回是否删除成功</returns>
        public bool Delete(string pdID)
        {
            SqlParameter[] parameters = {
					new SqlParameter("@pdID", SqlDbType.Int)};
            parameters[0].Value = pdID;

            return DbHelperSQL.GetIsRunOK("UP_Products_DisCount_Delete", parameters);
        }
        
        /// <summary>删除一条数据
        ///      <remarks>2011-01-21 河北大学信管团队</remarks>
        /// </summary>
        /// <param name="pdID">编号</param>
        /// <returns>返回是否删除成功</returns>
        public string GetDisCount(string siID)
        {
            SqlParameter[] parameters = {
					new SqlParameter("@siID", SqlDbType.VarChar,20)};
            parameters[0].Value = siID;

            return DbHelperSQL.GetNo1("UP_Products_DisCount_GetDisCount", parameters);
        }

        /// <summary>批量删除记录
        ///      <remarks>2011-01-21 河北大学信管团队</remarks>
        /// </summary>
        /// <param name="pdIDlist">编号</param>
        /// <returns>返回删除的记录条数</returns>
        public int DeleteList(string pdIDlist)
        {
            int i = 0;
            try
            {
                string[] pdID = pdIDlist.Split(',');
                foreach (string str in pdID)
                {
                    if (Delete(str))
                    {
                        i++;
                    }
                }
                return i;
            }
            catch
            {
                return i;
            }
        }

        /// <summary>得到一个对象实体
        ///      <remarks>2011-01-21 河北大学信管团队</remarks>
        /// </summary>
        /// <param name="pdID">编号</param>
        /// <returns>返回Model</returns>
        public IMIS_ERP.Model.Products_DisCount GetModel(int pdID)
        {
            SqlParameter[] parameters = {
					new SqlParameter("@pdID", SqlDbType.Int)};
            parameters[0].Value = pdID;

            IMIS_ERP.Model.Products_DisCount model = new IMIS_ERP.Model.Products_DisCount();
            DataSet ds = DbHelperSQL.RunProcedure("UP_Products_DisCount_GetModel", parameters, "ds");
            if (ds.Tables[0].Rows.Count > 0)
            {
                if (ds.Tables[0].Rows[0]["pdID"].ToString() != "")
                {
                    model.pdID = int.Parse(ds.Tables[0].Rows[0]["pdID"].ToString());
                }
                model.pdProvince = ds.Tables[0].Rows[0]["pdProvince"].ToString();
                model.pdCity = ds.Tables[0].Rows[0]["pdCity"].ToString();
                model.pdArea = ds.Tables[0].Rows[0]["pdArea"].ToString();
                model.pdPID = ds.Tables[0].Rows[0]["pdPID"].ToString();
                if (ds.Tables[0].Rows[0]["pdDisCount"].ToString() != "")
                {
                    model.pdDisCount = decimal.Parse(ds.Tables[0].Rows[0]["pdDisCount"].ToString());
                }
                if (ds.Tables[0].Rows[0]["pdBeginTime"].ToString() != "")
                {
                    model.pdBeginTime = DateTime.Parse(ds.Tables[0].Rows[0]["pdBeginTime"].ToString());
                }
                if (ds.Tables[0].Rows[0]["pdEndTime"].ToString() != "")
                {
                    model.pdEndTime = DateTime.Parse(ds.Tables[0].Rows[0]["pdEndTime"].ToString());
                }
                return model;
            }
            else
            {
                return null;
            }
        }

        /// <summary>获得数据列表
        ///     <remarks>2011-01-21 河北大学信管团队</remarks>
        /// </summary>
        /// <param name="strWhere">查询条件</param>
        /// <returns>返回DataSet</returns>
        public DataSet GetList(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select pdID,pdProvince,pdCity,pdArea,pdPID,pdDisCount,pdBeginTime,pdEndTime ");
            strSql.Append(" FROM Products_DisCount ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            return DbHelperSQL.Query(strSql.ToString());
        }

        /// <summary>获得前几行数据
        ///     <remarks>2011-01-21 河北大学信管团队</remarks>
        /// </summary>
        /// <param name="Top">行数</param>
        /// <param name="strWhere">条件</param>
        /// <param name="filedOrder">排序</param>
        /// <returns>返回DataSet</returns>
        public DataSet GetList(int Top, string strWhere, string filedOrder)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select ");
            if (Top > 0)
            {
                strSql.Append(" top " + Top.ToString());
            }
            strSql.Append(" pdID,pdProvince,pdCity,pdArea,pdPID,pdDisCount,pdBeginTime,pdEndTime ");
            strSql.Append(" FROM Products_DisCount ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            strSql.Append(" order by " + filedOrder);
            return DbHelperSQL.Query(strSql.ToString());
        }

        /*
        /// <summary>分页获取数据列表
        ///     <remarks>2011-01-21 河北大学信管团队</remarks>
        /// </summary>
        /// <param name="PageSize">每页条数</param>
        /// <param name="PageIndex">页码</param>
        /// <param name="strWhere">条件</param>
        /// <returns>返回DataSet</returns>
        public DataSet GetList(int PageSize,int PageIndex,string strWhere)
        {
            SqlParameter[] parameters = {
                    new SqlParameter("@tblName", SqlDbType.VarChar, 255),
                    new SqlParameter("@fldName", SqlDbType.VarChar, 255),
                    new SqlParameter("@PageSize", SqlDbType.Int),
                    new SqlParameter("@PageIndex", SqlDbType.Int),
                    new SqlParameter("@IsReCount", SqlDbType.Bit),
                    new SqlParameter("@OrderType", SqlDbType.Bit),
                    new SqlParameter("@strWhere", SqlDbType.VarChar,1000),
                    };
            parameters[0].Value = "Products_DisCount";
            parameters[1].Value = "ID";
            parameters[2].Value = PageSize;
            parameters[3].Value = PageIndex;
            parameters[4].Value = 0;
            parameters[5].Value = 0;
            parameters[6].Value = strWhere;	
            return DbHelperSQL.RunProcedure("UP_GetRecordByPage",parameters,"ds");
        }*/

        #endregion  Method
    }
}

